import React, { Component } from 'react'
import '../css/bases.css'
import MyTable from '../../component/myTable';
import MyForm from '../../component/myForm';
class RoleList extends Component {
    constructor(props) {
        super(props);
        this.state = {
            selectUrl: 'api.sysRoleList',
            /* tableInfo  */
            tableInfo: {
                delectUrl: '1111111111',
                search:{
                    searchUrl: 'api.tPipeDeviceList',
                    info: [
                        { label: '角色名称', type: 'input', key: 'roleName' },
                    ]
                },
                btn: [
                    { label: '新增', key: 'listId', type: 'add' },
                    { label: '批量刪除', key: 'listId', type: 'rowDelect' }
                ],
                tableEdit:false,
                columns: [
                    { title: '角色名称', dataIndex: 'roleName', align: 'center' },
                    // {
                    //     title: '状态', dataIndex: 'status', align: 'center', render: (text) => {
                    //         let status = [{ id: 1, name: '正常' }, { id: 0, name: '无效' }];
                    //         let idx = status.findIndex((obj) => { return obj.id === text })
                    //         return <div>{status[idx].name}   </div>
                    //     }
                    // },
                    { title: '', dataIndex: 'createTime', align: 'center' },
                    { title: '', dataIndex: 'createUser', align: 'center' },
                    { title: '机构ID', dataIndex: 'orgId', align: 'center' },
                ]
            },
            formInfo:{
                visible: false,
                addUrl: 'api.sysAdminLogAdd',
                updateUrl: 'api.sysAdminLogUpdate',
                label: [
                    { theKey: 'id', type: 'hidden', label: 'id', master: false, width: '100%' },
                    { theKey: 'roleName', type: 'text', label: '角色名称', master: false},
                    // { theKey: 'status', type: 'text', label: '状态', master: false,info:[{id:1,name:'正常'},{id:0,name:'无效'}]},
                    // { theKey: 'createTime', type: 'text', label: '', master: false },
                    // { theKey: 'createUser', type: 'text', label: '', master: false },
                    // { theKey: 'orgId', type: 'text', label: '机构ID', master: false },
                ],
                info: '',
            }
        }
    }
    componentDidMount() {

    }
    /* myTable back */
    tablaBack = (type, info) => {
        if (type === 'update') {
            this.setState({
                myFormInfo: Object.assign({}, this.state.myFormInfo, { visible: true, info: info })
            })
        } else if (type === 'num') {
            this.selectInfo(info, false)
        } else if (type === 'size') {
            this.setState({
                myTableInfo: Object.assign({}, this.state.myTableInfo, { pageSize: info })
            })
            this.selectInfo(false, info)
        } else if (type === 'delect') {
            this.selectInfo();
        }
    }
    /* form back */
    formBack = (type, info) => {
        if (type === 'close') {

        } else if (type === 'addUp') {
            this.selectInfo();
        }
        this.setState({
            myFormInfo: Object.assign({}, this.state.myFormInfo, { visible: false, info: {} })
        })
    }
    /* search back */
    searchBack = (type, info) => {
        if (type === 'add') {
            this.setState({
                myFormInfo: Object.assign({}, this.state.myFormInfo, { visible: true, info: {} })
            })
        } else if (type === 'search') {
            this.setState({
                myTableInfo: Object.assign({}, this.state.myTableInfo, { info: info })
            })
        }
    }
    render() {
        return (
            <div>
                <MyForm formInfo={this.state.formInfo} ></MyForm>
                <MyTable info={this.state.tableInfo}></MyTable>
            </div>
        )
    }
}
export default RoleList;